package com.centaline.androidsalesblog.rx.database;

import com.centaline.androidsalesblog.constants.CommonConstant;
import com.centaline.androidsalesblog.model.businissobject.DropBo;
import com.centaline.androidsalesblog.model.databaseobject.RailLineDo;
import com.centaline.androidsalesblog.model.databaseobject.RailWayDo;

import java.util.ArrayList;

import rx.functions.Func1;

/**
 * 下拉菜单-地铁
 * Created by guilin on 16/1/25.
 */
public class MetroFunc1 implements Func1<ArrayList<RailLineDo>, ArrayList<DropBo>> {

    @Override
    public ArrayList<DropBo> call(ArrayList<RailLineDo> railLineDos) {
        final ArrayList<DropBo> list = new ArrayList<>();
        DropBo dropBo1, dropBo2;
        dropBo1 = new DropBo(20);
        dropBo1.setText(CommonConstant.DROP_TEXT_NO_LIMITED);
        dropBo1.setValue(CommonConstant.DROP_VALUE_NULL);
        list.add(dropBo1);
        for (RailLineDo railLineDo : railLineDos) {
            dropBo1 = new DropBo(20);
            dropBo1.setText(railLineDo.getRailLineName());
            dropBo1.setValue(String.valueOf(railLineDo.getRailLineID()));
            ArrayList<DropBo> temp = new ArrayList<>();
            dropBo2 = new DropBo(20);
            dropBo2.setText(CommonConstant.DROP_TEXT_NO_LIMITED);
            dropBo2.setValue(CommonConstant.DROP_VALUE_NULL);
            temp.add(dropBo2);
            final ArrayList<RailWayDo> railWayDos = railLineDo.getList();
            for (RailWayDo railWayDo : railWayDos) {
                dropBo2 = new DropBo(20);
                dropBo2.setText(railWayDo.getRailWayName());
                dropBo2.setValue(String.valueOf(railWayDo.getRailWayID()));
                temp.add(dropBo2);
            }
            dropBo1.setChildrenList(temp);
            list.add(dropBo1);
        }
        return list;
    }

}
